package com.cci.kangdao.dao;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mybatis.spring.annotation.MapperScan;

import java.util.List;
import java.util.Map;

@MapperScan
public interface WorkOrderDrDao {

    @Select("select OrderNo from WorkOrderDR_T where ID = #{id,jdbcType=BIGINT}")
    String getOrderNoById(Long id);

    @Select("select SecretKey from WorkOrderDR_T where ID = #{id,jdbcType=BIGINT}")
    String getSecretKeyById(Long id);

    @Select("select top 1 * from WorkOrderDR_T where OrderNo = #{drOrderNo}")
    Map<String,Object> getDRWorkOrderByOrderNo(String drOrderNo);

    //根据诊断工单id获取所有执行过的方案信息
    @Select("select c.* from WorkOrderDR_T a\n" +
            "inner join DRFaultInfo_T b on a.ID = b.OrderId and b.Flag = 0\n" +
            "inner join WorkOrderSolution_T c on b.ID = c.FCARecordId and IsWorked !=0\n" +
            "where a.ID = #{drOrderId}")
    List<Map<String,Object>> getDoneSolutionIDListByOrderId(long drOrderId);

    @Select("select * from WorkOrderDR_T where ID = #{orderid}")
    Map<String,Object> getDRWorkOrderById(Long orderid);

    @Select("select Count(1) from WorkOrderDR_T where WFOrderId = #{orderId} and Flag = 0")
    Integer getDRWorkOrderByOrderId(Long orderId);

    @Select("select top 1 isnull(SMN,' ')  from WorkOrderDR_T where Creator=#{creator}  order by id desc")
    String getLastSMNCDSWorkorder(@Param("creator") Long creator);

    /**
     * 根据诊断工单id 查询是否满足维修确认条件 返回零件集合
     * @param orderId
     * @return
     */
    int isFitRepairAck(@Param("orderId") Long orderId);

    /**
     * 根据零件名称判断零件是否有id
     * @param nameList
     * @return
     */
    int isComponentId(@Param("nameList")List<String> nameList);
}
